<?
if (GetParam("nobkt","") && GetParam("FormName","")) {
		$SQL = "SELECT *,if(dk='K','D','K') as dk FROM ais_memorial WHERE nobkt='".GetParam("nobkt","")."' AND urut<>999 AND skada not like'".GetPPNSkada()."%' ";
		$MyResult = $DBConnection->dbc->get_results($SQL,ARRAY_A);
		//$js_script  = "<script>\n";
		if ($MyResult){
			foreach ($MyResult as $RowResult) {
				$n++;
//				$js_script .= "  alert('test');";
				$js_script .= "  window.opener.document.getElementById('$n').style.display = 'block';\n";
				$js_script .= "  window.opener.document.".GetParam("FormName","").".skada".$n.".value = \"".$RowResult["skada"]."\";\n";
				$js_script .= "  window.opener.document.".GetParam("FormName","").".uraian".$n.".value = \"".$RowResult["uraian"]."\";\n";
				$js_script .= "  window.opener.document.".GetParam("FormName","").".kdact".$n.".value = \"".$RowResult["kdact"]."\";\n";
				$js_script .= "  window.opener.document.".GetParam("FormName","").".dk".$n.".value = \"".$RowResult["dk"]."\";\n";
				$js_script .= "  window.opener.document.".GetParam("FormName","").".noorder".$n.".value = \"".$RowResult["noorder"]."\";\n";
				$js_script .= "  window.opener.document.".GetParam("FormName","").".noref".$n.".value = \"".GetParam("nobkt","")."\";\n";
				$js_script .= "  window.opener.document.".GetParam("FormName","").".jumlah".$n.".value = \"".FormatNumber($RowResult["jumlah"],2)."\";\n";
				$js_script .= "  window.opener.document.".GetParam("FormName","").".cbm".$n.".value = \"".$RowResult["cbm"]."\";\n";
				$js_script .= "  window.opener.document.".GetParam("FormName","").".dol".$n.".value = \"".$RowResult["dol"]."\";\n";
				$js_script .= "  window.opener.document.".GetParam("FormName","").".jenis".$n.".value = \"".$RowResult["jenis"]."\";\n";
			}
		}

		$SQL = "SELECT *,if(dk='K','D','K') as dk FROM ais_memorial WHERE nobkt='".GetParam("nobkt","")."' AND urut=999";
		$MyResult = $DBConnection->dbc->get_row($SQL);

		$js_script .= "  window.opener.document.".GetParam("FormName","").".skada999.value = \"".$MyResult->skada."\";\n";
		$js_script .= "  window.opener.document.".GetParam("FormName","").".uraian999.value = \"".$MyResult->uraian."\";\n";
		$js_script .= "  window.opener.document.".GetParam("FormName","").".kdact999.value = \"".$MyResult->kdact."\";\n";
		$js_script .= "  window.opener.document.".GetParam("FormName","").".dk999.value = \"".$MyResult->dk."\";\n";
		$js_script .= "  window.opener.document.".GetParam("FormName","").".noorder999.value = \"".$MyResult->noorder."\";\n";
		$js_script .= "  window.opener.document.".GetParam("FormName","").".noref999.value = \"".GetParam("nobkt","")."\";\n";
		$js_script .= "  window.opener.document.".GetParam("FormName","").".total_trans.value = \"".FormatNumber($MyResult->jumlah,2)."\";\n";

		$js_script .= "  window.opener.document.".GetParam("FormName","").".debtur.value = \"".$MyResult->debtur."\";\n";
		$js_script .= "  window.opener.document.".GetParam("FormName","").".debnam.value = \"".$MyResult->debnam."\";\n";


		$js_script .= "  self.close();\n";		
		print $js_script;    		
		exit;
}

?>
<html>
<script type="text/javascript" src="<?=$ROOT_JS_DIR?>/common.js"></script>
<script type="text/javascript" src="<?=$ROOT_JS_DIR?>/jsmasks.js"></script>
<body>
<h1>Loading data...</h1>
<?

define("PRIMARY_KEY","nik");
$FileName       = "ais_transaction_advsummary_rpc.php";
$HTMLFormName   = "CashBankForm";

if (GetParam("tglbkt","") && GetParam("curr","")) {
	list($day,$month,$year) = explode("/",GetParam("tglbkt",""));
	$SQL = "SELECT rate FROM ais_kurssi WHERE tglbkt <= '$year-$month-$day' AND curr='".GetParam("curr","")."' ORDER BY tglbkt DESC LIMIT 1";
//	print $SQL;
	$rate = $DBConnection->dbc->get_var($SQL);
	if ($rate) {
		$js_script  = "<script>\n";
		$js_script .= "  parent.document.".$HTMLFormName.".rate.value = '$rate';\n";		
		$js_script .= "  oMask = new Mask('#,###.#0', 'number');\n";
		$js_script .= "  parent.document.".$HTMLFormName.".rate.value = oMask.format(parent.document.$HTMLFormName.rate.value);\n";
		$js_script .= "</script>\n";		
		print $js_script;		
	} else {
		$js_script  = "<script>\n";
		$js_script .= "  parent.document.".$HTMLFormName.".rate.value = '0';\n";		
		$js_script .= "  oMask = new Mask('#,###.#0', 'number');\n";
		$js_script .= "  parent.document.".$HTMLFormName.".rate.value = oMask.format(parent.document.$HTMLFormName.rate.value);\n";
		$js_script .= "</script>\n";		
		print $js_script;
	}
} elseif (GetParam("thbl","") && GetParam("idx","")) {
	$SQL   = "SELECT skada FROM tblreceipt WHERE kdreceipt=".GetParam("thbl","");
	$skada = $DBConnection->dbc->get_var($SQL);
	if (strlen($skada)) {
		$js_script  = "<script>\n";
		$js_script .= "  parent.document.$HTMLFormName.skada".GetParam("idx","").".value = '$skada'";
		$js_script .= "</script>\n";
	} else {
		$js_script  = "<script>\n";
		$js_script .= "  parent.document.$HTMLFormName.skada".GetParam("idx","").".value = ''";
		$js_script .= "</script>\n";		
	}
	print $js_script;
} elseif (GetParam("ledger","") && GetParam("trsto","")) {
		list($day,$month,$year) = explode("/",GetParam("ledger",""));
	    $SQL   = "SELECT count(*) FROM ais_history_ledger WHERE month='$month' AND year = '$year' AND status='open'";
	    $ExistPeriod = $DBConnection->dbc->get_var($SQL);
		if (!$ExistPeriod) {
			$js_script  = "<script>\n";
			$js_script .= "  parent.document.$HTMLFormName.".GetParam("trsto","").".value = '';\n";
			$js_script .= "  alert('Invalid Date, Period Allready Closed!');\n";
			$js_script .= "  parent.document.$HTMLFormName.".GetParam("trsto","").".focus();\n";
			$js_script .= "</script>\n";
	    }
	print $js_script;	    
} elseif (GetParam("bank","")) {
	    $SQL   = "SELECT coa FROM tblbank WHERE kdbank='".GetParam("bank","")."'";
	    $coa = $DBConnection->dbc->get_var($SQL);
	    if ($coa) {
			$js_script  = "<script>\n";
			$js_script .= "  parent.document.$HTMLFormName.skada999.value = '$coa';\n";
			$js_script .= "</script>\n";		    
		}
		print $js_script;
	
} elseif (GetParam("cash","")) {
	    $SQL   = "SELECT coa FROM tblcash WHERE kdcash='".GetParam("cash","")."'";
	    $coa = $DBConnection->dbc->get_var($SQL);
	    if ($coa) {
			$js_script  = "<script>\n";
			$js_script .= "  parent.document.$HTMLFormName.skada999.value = '$coa';\n";
			$js_script .= "</script>\n";		    
		}
		print $js_script;
	
}


?>
